package com.example.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.utils.R;
import com.example.system.entity.RegionInfo;
import com.example.system.mapper.RegionInfoMapper;
import com.example.system.service.IRegionInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 中国地区信息 服务实现类
 * </p>
 *
 * @author 王鹤蒲
 * @since 2023-08-27
 */
@Service
public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionInfo> implements IRegionInfoService {

    private static final Logger log = LoggerFactory.getLogger(RegionInfoServiceImpl.class);

    @Autowired
    private RegionInfoMapper regionInfoMapper;

    @Override
    public R queryAllRegionInfoList() {
       List<RegionInfo> provinceList=regionInfoMapper.queryAllByLevel("1");
       for(RegionInfo province:provinceList){
       List<RegionInfo> cityList =regionInfoMapper.queryAllBySuperiorCode(province.getCode());
       for(RegionInfo city :cityList){
          List<RegionInfo>  areaList=regionInfoMapper.queryAllBySuperiorCode(city.getCode());
          for (RegionInfo area:areaList){
              List<RegionInfo> streetList=regionInfoMapper.queryAllBySuperiorCode(area.getCode());
              area.setChildrenList(streetList);
          }
          city.setChildrenList(areaList);
       }
       province.setChildrenList(cityList);
       }
        System.out.println(provinceList);
        return R.success(provinceList);
    }
}
